/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;

import edu.pku.sei.modeler.internal.MetaModelingProject;
import edu.pku.sei.modeler.jet.ui.GenerationWizard;
import edu.pku.sei.modeler.model.core.MetaModel;

/**
 * @author zhaoyi
 *
 */
public class CodeGenerationAction extends Action {
	IWorkbenchPage workbenchPage;
	private Object obj;
	
	public IWorkbenchPage getWorkbenchPage() {
		return workbenchPage;
	}
	public void setWorkbenchPage(IWorkbenchPage workbenchPage) {
		this.workbenchPage = workbenchPage;
	}
	public CodeGenerationAction(){
		super();
		this.setText("Ge&nerate Code");
		setToolTipText("Ge&nerate Code");
		this.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
				getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
	}
	public void setTreeObj(Object obj) {
		this.obj = obj;
	}
	public void run()
	{
		if(obj instanceof MetaModel) {
			MetaModel model = (MetaModel)obj;
			System.out.println(model.getName());
			Shell shell = new Shell();
			WizardDialog dialog = new WizardDialog(shell,new GenerationWizard(model));
			dialog.setPageSize(-1,300);
			dialog.open();
		}
		else if(obj instanceof MetaModelingProject) {
			MetaModelingProject proj = (MetaModelingProject)obj;
			MetaModel model = proj.getModel();
			System.out.println(model.getName());
			Shell shell = new Shell();
			WizardDialog dialog = new WizardDialog(shell,new GenerationWizard(model));
			dialog.setPageSize(-1,300);
			dialog.open();
		}
	}
}
